<?php
/**
 * Notes:
 * User: LiaoHong
 * Date: 2025/10/22
 * Time: 10:47
 **/


namespace App\Services\User;


use App\Models\User\Logininfor;
use App\Models\User\OperLog;

class LogManageService
{
    /**
     * @Notes:操作日志
     * @author: Liao Hong
     * @Time: 2025/10/22   11:49
     * @Interface actionLog
     */
    public function actionLog($parmas=[]){
        $query = [];
        if(isset($parmas['oper_ip']) && !empty($parmas['oper_ip'])){
            $query[] = ['oper_ip','=',$parmas['oper_ip']];
        }
        if(isset($parmas['title']) && !empty($parmas['title'])){
            $query[] = ['title','like','%'.$parmas['title'].'%'];
        }
        if(isset($parmas['oper_name']) && !empty($parmas['oper_name'])){
            $query[] = ['oper_name','=',$parmas['oper_name']];
        }
        if(isset($parmas['business_type']) && !empty($parmas['business_type'])){
            $query[] = ['business_type','=',$parmas['business_type']];
        }
        if(isset($parmas['status'])){
            $query[] = ['status','=',$parmas['status']];
        }
        if(isset($parmas['oper_time']['beginTime']) && !empty($parmas['oper_time']['beginTime'])){
            $query[] = ['oper_time','>',$parmas['oper_time']['beginTime']];
        }
        if(isset($parmas['oper_time']['endTime']) && !empty($parmas['oper_time']['endTime'])){
            $query[] = ['oper_time','<',$parmas['oper_time']['endTime']];
        }
        $limit = isset($parmas['limit']) ? $parmas['limit'] : 10;
        $row = OperLog::query()->where($query)->paginate($limit);
        $row = empty($row) ?  [] :$row->toArray();
        return $row;
    }

    /**
     * @Notes:登录日志
     * @author: Liao Hong
     * @Time: 2025/10/22   11:49
     * @Interface loginlog
     */
    public function loginlog($params=[])
    {
        $query = [];
        if(isset($params['ipaddr']) && !empty($params['ipaddr'])){
            $query[] = ['ipaddr','=',$params['ipaddr']];
        }
        if(isset($params['user_name']) && !empty($params['user_name'])){
            $query[] = ['user_name','like','%'.$params['user_name'].'%'];
        }
        if(isset($params['status']) && $params['status'] !==''){
            $query[] = ['status','=',$params['status']];
        }
        if(isset($params['login_time']['beginTime']) && !empty($params['login_time']['beginTime'])){
            $query[] = ['login_time','>',$params['login_time']['beginTime']];
        }
        if(isset($params['login_time']['endTime']) && !empty($params['login_time']['endTime'])){
            $query[] = ['login_time','<',$params['login_time']['endTime']];
        }
        $limit = isset($params['limit']) ? $params['limit'] : 10;
        $row = Logininfor::query()->where($query)->paginate($limit);
        $row = empty($row) ?  [] :$row->toArray();
        return $row;
    }

}
